package com.example.module_home.adapter

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.example.lib_common.view.entity.NoticeEntity
import com.example.lib_common.view.vm.BaseViewModel
import com.example.module_home.R

class AnnouncementAdapter:BaseQuickAdapter<NoticeEntity,BaseViewHolder>(R.layout.item_notice) {
    override fun convert(holder: BaseViewHolder, item: NoticeEntity) {
        holder.getView<TextView>(R.id.item_time).text=item.title
        holder.getView<TextView>(R.id.item_content).text=item.content
        holder.getView<TextView>(R.id.item_time).text=item.publishTime
    }
}

//class AnnouncementAdapter(announcements: List<NoticeEntity> = emptyList()) : RecyclerView.Adapter<AnnouncementAdapter.AnnouncementViewHolder>() {
//
//    private var announcementsList: List<NoticeEntity> = announcements
//        set(value) {
//            field = value
//            notifyDataSetChanged()
//        }
//
//    // 添加data属性以兼容现有用法
//    var data: MutableList<NoticeEntity> = announcements.toMutableList()
//        set(value) {
//            field = value
//            announcementsList = value
//        }
//
//    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): AnnouncementViewHolder {
//        val view = LayoutInflater.from(parent.context).inflate(R.layout.item_notice, parent, false)
//        return AnnouncementViewHolder(view)
//    }
//
//    override fun onBindViewHolder(holder: AnnouncementViewHolder, position: Int) {
//        val item = announcementsList[position]
//        holder.bind(item)
//    }
//
//    override fun getItemCount(): Int = announcementsList.size
//
//    fun updateData(newAnnouncements: List<NoticeEntity>) {
//        announcementsList = newAnnouncements
//        data.clear()
//        data.addAll(newAnnouncements)
//    }
//
//    // ViewHolder类保持不变
//    class AnnouncementViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
//        private val titleTextView: TextView = itemView.findViewById(R.id.item_title)
//        private val contentTextView: TextView = itemView.findViewById(R.id.item_content)
//        private val timeTextView: TextView = itemView.findViewById(R.id.item_time)
//
//        fun bind(item: NoticeEntity) {
//            titleTextView.text = item.title
//            contentTextView.text = item.content
//            timeTextView.text = item.publishTime
//        }
//    }
//}
